package net.knightwatch.kwtools.walkthrough; 

import java.util.ArrayList;

import net.knightwatch.kwtools.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;


public class PotentialArrayAdapter extends ArrayAdapter<Potential> {

	public static final String TAG = "PotentialArrayAdapter";
	int resource;
	Context context;
	public PotentialArrayAdapter(Context context, int textViewResourceId, ArrayList<Potential> potentials){
		super(context, textViewResourceId, potentials);
		// PotentialArrayAdapter constructor stub
		this.resource=textViewResourceId;
	}
	@Override
	public View getView(int posistion, View convertView, ViewGroup parent){
		LinearLayout potentialView;
		// Get the current potential object
		Potential potential = getItem(posistion);
		
		// Inflate the view
		if(convertView == null){
			potentialView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, potentialView, true);
		}
		else
		{
			potentialView = (LinearLayout) convertView;
		}
		
		// Get the text boxes from the listitem.xml file for the potentials
		TextView potentialName = (TextView)potentialView.findViewById(R.id.txtPotentialName);
		TextView potentialItemCount = (TextView)potentialView.findViewById(R.id.txtPotentialExtra);
		potentialName.setText(potential.getName());
		potentialItemCount.setText("Total Items: " + potential.getItemCount());
		return potentialView;
	}
}
